<div style="padding: 5px 0px; margin: 10px 0px 10px 10px;" class="filter">
    <select id="historyQueryParamGameId">
    </select>
    日期：
    <input id="historyQueryParamOpenTime" readonly/>
</div>

<div style="min-height: 320px;">
    <table class="u-table2 play_tab_10" id="history_table" style="margin: 0px 0px 40px 10px; width: 1000px;">
        <thead>
        </thead>
        <tbody></tbody>
    </table>

    <div class="page_info">
        <div id="listPage" class="megas512 zxf_pagediv"></div>    
    </div>
    <div style="height: 50px;"></div>
</div>
<style type="text/css">
    #history_table th {
        height: 23px;
        font-weight: bold;
        font-size: 16px;
    }
    td.red {
        color: red !important;
    }
    td.blue {
        color: blue !important;
    }
    td.green {
        color: green !important;
    }
    .filter .am-btn {
        font-size: 12px;
        padding-top: 4px;
        padding-bottom: 4px;
        border: 1px solid #ccc;
    }
    .filter .am-selected {
        width: 120px;
    }
    .filter .am-selected-list .am-selected-text {
        font-size: 12px;
    }
    #historyQueryParamOpenTime {
        border: 1px solid #ccc;
        padding: 3px 6px 3px 6px;
    }
</style>

<script>
    // 填充select
    $("#historyQueryParamGameId").selected();
    var games = get_game_list();
    for (var i in games) {
        $("#historyQueryParamGameId").append('<option value="' + games[i] + '">' + get_game_display_name(games[i]) + "</option>");
    }
    $("#historyQueryParamGameId").val(game);
    $("#historyQueryParamGameId").trigger('changed.selected.amui');

    $("#historyQueryParamOpenTime").datepicker({
        format: 'yyyy-mm-dd'
    });
    $("#historyQueryParamOpenTime").datepicker("setValue", new Date().Format("yyyy-MM-dd"));

    $("#historyQueryParamGameId").change(function() {
        queryKjjg();
    });
    $("#historyQueryParamOpenTime").change(function() {
        queryKjjg();
    });

    var queryKjjg = Util.queryTemplate($("#history_table tbody"), ".zxf_pagediv", $(".button button"), function(page, size, cb) {
        var g = $("#historyQueryParamGameId").val();
        var data = {
            pageNum: page,
            pageSize: size || 20,
            type: g,
        };
        var start = new Date($("#historyQueryParamOpenTime").val()).getTime() - 8 * 3600 * 1000;
        var end = start + 24 * 3600 * 1000;

        if (g == 'lhc' && start) {
            start = null;
            end = null;
        }
        else if (new Date().getTime() - start < 2 * 3600 * 1000) {
            start = start - 2 * 3600 * 1000;
        }
        
        if (start) data.start = start;
        if (end) data.end = end;
        
        startLoading();
        CMD.lottery_query(data, function(r) {
            stopLoading();
            cb(r);
        });
    }, function(table, list, sum) {
        var table = $("#history_table");
        $("#history_table thead").empty();
        $("#history_table tbody").empty();
        var g = $("#historyQueryParamGameId").val();
        switch (g) {
            case "bjpk10":
            case "zypk10":
                _drawPk10(table, list); break;
            case "cqssc":
            case "xjssc":
            case "tjssc":
            case "zyssc":
            case "ffcqq":
                _drawSsc(table, list); break;
            case "cqkl10":
                _drawCqkl10(table, list); break;
            case "gdkl10":
            case "zykl10":
                _drawTen(table, list); break;
            case "gd115":
            case "zy115":
                _draw115(table, list); break;
            case "bjkl8":
            case "zykl8":
                _drawkl8(table, list); break;
            case "jsk3":
            case "zyk3":
                _drawk3(table, list); break;
            case "lhc":
                _drawlhc(table, list); break;
            }
    });

    // pk10绘制
    function _drawPk10(table, list) {
        var tr = '<tr><th style="width: 100px" rowspan="2">期数</th><th style="width: 100px" rowspan="2">开奖时间</th><th colspan="10">开出号码</th><th colspan="3" rowspan="2">冠亚军和</th><th colspan="5" rowspan="2">1~5龙虎</th></tr><tr><th>第一名</th><th>第二名</th><th>第三名</th><th>第四名</th><th>第五名</th><th>第六名</th><th>第七名</th><th>第八名</th><th>第九名</th><th>第十名</th></tr>';
        table.find("thead").append(tr);

        for (var i in list) {
            var o = list[i];
            if (!o.time.startsWith($("#historyQueryParamOpenTime").val())) continue;
            var tr = $("<tr></tr>");
            tr.append("<td>" + o.issue + "</td>");
            tr.append("<td>" + o.time + "</td>");

            // 5球
            var l = '<td><span class="ball c-n__index__"></span></td>';
            var red = o.red
            for (var j in red) {
                tr.append(l.replace(/__index__/, parseInt(red[j])));
            }
            gy = parseInt(red[0]) + parseInt(red[1]);
            tr.append("<td>" + gy + "</td>");
            if (gy > 11) tr.append("<td class='red'>大</td>");
            else tr.append("<td>小</td>");
            if (gy % 2 == 0) tr.append("<td class='red'>双</td>");
            else tr.append("<td>单</td>");

            // 1~5龙虎
            for (var j = 0; j < 5; j++) {
                var v0 = parseInt(red[j]), v1 = parseInt(red[9 - j]);
                if (v0 > v1) tr.append("<td class='red'>龙</td>");
                else tr.append("<td>虎</td>");
            }

            table.find("tbody").append(tr);
        }
    }

    // 时时彩
    function _drawSsc(table, list) {
        var tr = '<tr><th style="width: 100px" rowspan="2">期数</th><th rowspan="2">开奖时间</th><th colspan="5">开出号码</th><th colspan="3" rowspan="2">总和</th><th rowspan="2">龙虎</th><th rowspan="2">前三</th><th rowspan="2">中三</th><th rowspan="2">后三</th></tr><tr><th>第1球</th><th>第2球</th><th>第3球</th><th>第4球</th><th>第5球</th></tr>';
        table.find("thead").append(tr);

        var gameRule = Util.getGameRule("cqssc");
        for (var i in list) {
            var o = list[i];
            if (o.time && !o.time.startsWith($("#historyQueryParamOpenTime").val())) continue;
            var tr = $("<tr></tr>");
            tr.append("<td>" + o.issue + "</td>");
            tr.append("<td>" + (o.time || '') + "</td>");

            // 5球
            var l = '<td class="menu1" style="width:45px;"><a class="T_SSC L_CQSSC"><span><b class="b__index__">num</b></span></a></td>';
            var red = o.red
            for (var j in red) {
                tr.append(l.replace(/__index__/, parseInt(red[j])));
            }
            
            // 总和
            var he = gameRule.he(red);
            tr.append("<td>" + he + "</td>");
            if (gameRule.isHeBig(red)) tr.append("<td class='red'>大</td>");
            else tr.append("<td>小</td>");
            if (gameRule.isHeOdd(red)) tr.append("<td>单</td>");
            else tr.append("<td class='red'>双</td>");

            // 龙虎
            if (gameRule.isLong(red)) 
                tr.append("<td class='red'>龙</td>");
            else if (gameRule.isHu(red))
                tr.append("<td>虎</td>");
            else if (gameRule.isHe(red))
                tr.append("<td class='blue'>和</td>");

            // 前三
            if (gameRule.isQian3BaoZi(red))
                tr.append("<td>豹子</td>");
            else if (gameRule.isQian3ShunZi(red))
                tr.append("<td>顺子</td>");
            else if (gameRule.isQian3DuiZi(red))
                tr.append("<td>对子</td>");
            else if (gameRule.isQian3BanShun(red))
                tr.append("<td>半顺</td>");
            else if (gameRule.isQian3ZaLiu(red))
                tr.append("<td>杂六</td>");

            // 中三
            if (gameRule.isZhong3BaoZi(red))
                tr.append("<td>豹子</td>");
            else if (gameRule.isZhong3ShunZi(red))
                tr.append("<td>顺子</td>");
            else if (gameRule.isZhong3DuiZi(red))
                tr.append("<td>对子</td>");
            else if (gameRule.isZhong3BanShun(red))
                tr.append("<td>半顺</td>");
            else if (gameRule.isZhong3ZaLiu(red))
                tr.append("<td>杂六</td>");

            // 后三
            if (gameRule.isHou3BaoZi(red))
                tr.append("<td>豹子</td>");
            else if (gameRule.isHou3ShunZi(red))
                tr.append("<td>顺子</td>");
            else if (gameRule.isHou3DuiZi(red))
                tr.append("<td>对子</td>");
            else if (gameRule.isHou3BanShun(red))
                tr.append("<td>半顺</td>");
            else if (gameRule.isHou3ZaLiu(red))
                tr.append("<td>杂六</td>");

            table.find("tbody").append(tr);
        }
    }

    // 重庆幸运农场
    function _drawCqkl10(table, list) {
        var tr = '<tr><th style="width: 100px" rowspan="2">期数</th><th rowspan="2">开奖时间</th><th colspan="8">开出号码</th><th colspan="4" rowspan="2">总和</th><th colspan="4" rowspan="2">1~4龙虎</th></tr><tr><th>第1球</th><th>第2球</th><th>第3球</th><th>第4球</th><th>第5球</th><th>第6球</th><th>第7球</th><th>第8球</th></tr>';
        table.find("thead").append(tr);

        var gameRule = Util.getGameRule("cqkl10");
        for (var i in list) {
            var o = list[i];
            if (!o.time.startsWith($("#historyQueryParamOpenTime").val())) continue;
            var tr = $("<tr></tr>");
            tr.append("<td>" + o.issue + "</td>");
            tr.append("<td>" + o.time + "</td>");

            var l = '<td> <div class="XYNCTerm"><b class="b__index__">__index__</b></div></td>';
            var red = o.red
            for (var j in red) {
                tr.append(l.replace(/__index__/g, (red[j])));
            }
            
            var he = gameRule.he(red);
            tr.append("<td>" + he + "</td>");
            if (gameRule.isHeBig(red)) tr.append("<td class='red'>大</td>");
            else if (gameRule.isHeSmall(red)) tr.append("<td>小</td>");
            else tr.append("<td class='blue'>和</td>");

            if (!gameRule.isOdd(he)) tr.append("<td class='red'>双</td>");
            else tr.append("<td>单</td>");
            if (gameRule.isWeiDa(he)) tr.append("<td class='red'>尾大</td>");
            else tr.append("<td>尾小</td>");

            // 1~4龙虎
            for (var i = 0; i < 4; i++) {
                if (gameRule.isLong(red, i)) tr.append("<td class='red'>龙</td>");
                else tr.append("<td>虎</td>");
            }

            table.find("tbody").append(tr);
        }
    }

    // 快乐10
    function _drawTen(table, list) {
        var tr = '<tr><th style="width: 100px" rowspan="2">期数</th><th rowspan="2">开奖时间</th><th colspan="8">开出号码</th><th colspan="4" rowspan="2">总和</th><th colspan="4" rowspan="2">1~4龙虎</th></tr><tr><th>第1球</th><th>第2球</th><th>第3球</th><th>第4球</th><th>第5球</th><th>第6球</th><th>第7球</th><th>第8球</th></tr>';
        table.find("thead").append(tr);

        var gameRule = Util.getGameRule("gdkl10");
        for (var i in list) {
            var o = list[i];
            if (!o.time.startsWith($("#historyQueryParamOpenTime").val())) continue;
            var tr = $("<tr></tr>");
            tr.append("<td>" + o.issue + "</td>");
            tr.append("<td>" + o.time + "</td>");

            var l = '<td><span class="ball c-b1">__index__</span></td>';
            var red = o.red
            for (var j in red) {
                tr.append(l.replace(/__index__/g, parseInt(red[j])));
            }
            
            var he = gameRule.he(red);
            tr.append("<td>" + he + "</td>");
            if (gameRule.isHeBig(red)) tr.append("<td class='red'>大</td>");
            else if (gameRule.isHeSmall(red)) tr.append("<td>小</td>");
            else tr.append("<td class='blue'>和</td>");

            if (!gameRule.isOdd(he)) tr.append("<td class='red'>双</td>");
            else tr.append("<td>单</td>");
            if (gameRule.isWeiDa(he)) tr.append("<td class='red'>尾大</td>");
            else tr.append("<td>尾小</td>");

            // 1~4龙虎
            for (var i = 0; i < 4; i++) {
                if (gameRule.isLong(red, i)) tr.append("<td class='red'>龙</td>");
                else tr.append("<td>虎</td>");
            }

            table.find("tbody").append(tr);
        }
    }

    // 11选5
    function _draw115(table, list) {
        var tr = '<tr><th style="width: 100px" rowspan="2">期数</th><th rowspan="2">开奖时间</th><th colspan="5">开出号码</th><th colspan="4" rowspan="2">总和</th><th rowspan="2">龙虎</th><th colspan="5" rowspan="2">1~5大小</th></tr><tr><th>第1球</th><th>第2球</th><th>第3球</th><th>第4球</th><th>第5球</th></tr>';
        table.find("thead").append(tr);

        var gameRule = Util.getGameRule("gd115");
        for (var i in list) {
            var o = list[i];
            if (!o.time.startsWith($("#historyQueryParamOpenTime").val())) continue;
            var tr = $("<tr></tr>");
            tr.append("<td>" + o.issue + "</td>");
            tr.append("<td>" + o.time + "</td>");

            var l = '<td><span class="ball c-b1">__index__</span></td>';
            var red = o.red
            for (var j in red) {
                tr.append(l.replace(/__index__/g, parseInt(red[j])));
            }
            
            var he = gameRule.he(red);
            tr.append("<td>" + he + "</td>");
            if (gameRule.isHeBig(red))
                tr.append("<td class='red'>大</td>");
            else if (gameRule.isHeSmall(red))
                tr.append("<td>小</td>");
            else tr.append("<td> </td>");
            if (gameRule.isHeOdd(red))
                tr.append("<td>单</td>");
            else
                tr.append("<td class='red'>双</td>");
            if (gameRule.isHeWeiBig(red))
                tr.append("<td class='red'>尾大</td>");
            else
                tr.append("<td>尾小</td>");

            // 龙虎
            if (gameRule.isLong(red))
                tr.append("<td class='red'>龙</td>");
            else if (gameRule.isHu(red))
                tr.append("<td>虎</td>");
            else if (gameRule.isHe(red))
                tr.append("<td class='blue'>和</td>");

            // 1~5大小
            for (var i = 0; i < 5; i++) {
                var v = parseInt(red[i]);
                if (gameRule.isBig(v)) tr.append("<td class='red'>大</td>");
                else if (gameRule.isSmall(v)) tr.append("<td>小</td>");
                else tr.append("<td class='blue'>和</td>");
            }

            table.find("tbody").append(tr);
        }
    }

    // 快乐8
    function _drawkl8(table, list) {
        var tr = '<tr><th style="width: 60px">期数</th><th>开奖时间</th><th colspan="20">开出号码</th><th colspan="4">总和</th><th colspan="2">比数量</th></tr>';
        table.find("thead").append(tr);

        var gameRule = Util.getGameRule("bjkl8");
        for (var i in list) {
            var o = list[i];
            if (!o.time.startsWith($("#historyQueryParamOpenTime").val())) continue;
            var tr = $("<tr></tr>");
            tr.append("<td>" + o.issue + "</td>");
            tr.append("<td>" + o.time + "</td>");

            var l = '<td> <div class="T_KL8"><span><b class="b__index__">__index__</b></span></div></td>';
            var red = o.red
            for (var j in red) {
                tr.append(l.replace(/__index__/g, (red[j])));
            }
            
            var he = gameRule.he(red);
            tr.append("<td>" + he + "</td>");
            if (gameRule.isHeBig(red)) tr.append("<td class='red'>大</td>");
            else if (gameRule.isHeSmall(red)) tr.append("<td>小</td>");
            else tr.append("<td class='blue'>和</td>");

            if (he % 2 ==  0) tr.append("<td class='red'>双</td>");
            else tr.append("<td>单</td>");

            if (gameRule.isJin(red)) tr.append("<td>金</td>");
            else if (gameRule.isMu(red)) tr.append("<td>木</td>");
            else if (gameRule.isShui(red)) tr.append("<td>水</td>");
            else if (gameRule.isHuo(red)) tr.append("<td>火</td>");
            else if (gameRule.isTu(red)) tr.append("<td>土</td>");

            if (gameRule.isQianDuo(red)) tr.append("<td class='red'>前多</td>");
            else if (gameRule.isHouDuo(red)) tr.append("<td>后多</td>");
            else tr.append("<td class='blue'>前后和</td>");

            if (gameRule.isDanDuo(red)) tr.append("<td>单多</td>");
            else if (gameRule.isShuangDuo(red)) tr.append("<td class='red'>双多</td>");
            else tr.append("<td class='blue'>单双和</td>");

            table.find("tbody").append(tr);
        }
    }

    // 快3
    function _drawk3(table, list) {
        var tr = '<tr><tr><th style="width: 100px" rowspan="2">期数</th><th rowspan="2">开奖时间</th><th colspan="3">开出骰子</th><th colspan="2" rowspan="2">总和</th></tr><tr><th>第1球</th><th>第2球</th><th>第3球</th></tr>';
        table.find("thead").append(tr);

        var gameRule = Util.getGameRule("jsk3");
        for (var i in list) {
            var o = list[i];
            if (!o.time.startsWith($("#historyQueryParamOpenTime").val())) continue;
            var tr = $("<tr></tr>");
            tr.append("<td>" + o.issue + "</td>");
            tr.append("<td>" + o.time + "</td>");

            var l = '<td> <div class="K3Term"><span><b class="b__index__ ml20">__index__</b></span></div></td>';
            var red = o.red
            for (var j in red) {
                tr.append(l.replace(/__index__/g, parseInt(red[j])));
            }
            
            var he = gameRule.he(red);
            tr.append("<td>" + he + "</td>");
            if (gameRule.isBaoZi(red)) tr.append("<td class='blue'>豹子</td>");
            else if (gameRule.isHeBig(red)) tr.append("<td class='red'>大</td>");
            else tr.append("<td>小</td>");

            table.find("tbody").append(tr);
        }
    }

    // 六合彩
    function _drawlhc(table, list) {
        var tr = '<tr><th colspan="2"></th><th colspan="7">号码</th><th colspan="4">总和</th><th colspan="5">特码</th></tr><tr><th width="70">期数</th><th width="90">开奖时间</th><th>正码一</th><th>正码二</th><th>正码三</th><th>正码四</th><th>正码五</th><th>正码六</th><th>特码</th><th>总数</th><th>单双</th><th>大小</th><th>七色波</th><th>单双</th><th>大小</th><th>合单双</th><th>合大小</th><th>大小尾</th></tr>';
        table.find("thead").append(tr);

        var gameRule = Util.getGameRule("lhc");
        for (var i in list) {
            var o = list[i];
            var tr = $("<tr></tr>");
            tr.append("<td>" + o.issue + "</td>");
            tr.append("<td>" + o.time + "</td>");

            var l = '<td> <i class="lhc_icon lhc_b__index__">__index__</i><br><span>__x__</span></td>';
            var red = o.red
            for (var j in red) {
                var l2 = l.replace(/__index__/g, red[j]);
                l2 = l2.replace(/__x__/, gameRule.getShengXiao(parseInt(red[j])));
                tr.append(l2);
            }
            
            // 总和
            var he = gameRule.he(red);
            tr.append("<td>" + he + "</td>");

            // 单双
            if (!gameRule.heOdd(red)) tr.append("<td class='red'>总和双</td>");
            else tr.append("<td class=''>总和单</td>");

            // 大小
            if (gameRule.heBig(red))  tr.append("<td class='red'>总和大</td>");
            else tr.append("<td class=''>总和小</td>");

            // 七色波
            var qi = gameRule.qiSeBo(red);
            if (qi == '红') tr.append("<td class='red'>红</td>");
            else if (qi == '蓝') tr.append("<td class='blue'>蓝</td>");
            else if (qi == '绿') tr.append("<td class='green'>绿</td>");
            else tr.append("<td class=''>和</td>");

            // 特码
            var te = parseInt(red[6]);
            if (te % 2 == 0) tr.append("<td class='red'>双</td>");
            else tr.append("<td class=''>单</td>");
            if (te >= 25) tr.append("<td class='red'>大</td>");
            else tr.append("<td class=''>小</td>");

            var he = Math.floor(te / 10) + (te % 10);
            if (te == 49) tr.append("<td class='blue'>和</td>")
            else if (he % 2 == 0) tr.append("<td class='red'>双</td>");
            else tr.append("<td class=''>单</td>");
            if (te == 49) tr.append("<td class='blue'>和</td>")
            else if (he >= 7) tr.append("<td class='red'>大</td>");
            else tr.append("<td class=''>小</td>");

            var wei = te % 10;
            if (wei >= 5) tr.append("<td class='red'>大</td>");
            else tr.append("<td class=''>小</td>");

            table.find("tbody").append(tr);
        }
    }
</script>